<?php

namespace App\Jobs\Admin;

use App\Models\Admin\Queue;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Throwable;
use App\Models\Admin\Test;

class sendMessage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $data;
    public function __construct($data)
    {
        //
        return $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        //
//        $model = Test::all();
//        $model = Test::limit(100)->get();
//        dd($model);
//        foreach ($model as $v){
//            dd($v->name);
//            $res = Queue::create([
//                'name'=>$v->name
//            ]);
//            if($res){
//                var_dump('成功');
//            }else{
//                var_dump('失败');
//            }
//
//        }

        $datas = $this->data->data;
        $res = Queue::create([
            'name'=>$datas
        ]);
        if($res){
            var_dump('成功');
        }else{
            var_dump('失败');
        }

    }

    /**
     * 任务未能处理
     *
     * @param  \Throwable  $exception
     * @return void
     */
    public function failed(Throwable $exception)
    {
        // 给用户发送失败通知, 等等...
        Log::channel('log')->debug($exception->getMessage());
    }

//    public function failed(Throwable $exception)
//    {
//        // 给用户发送失败通知, 等等...
//        Log::channel('log')->debug($exception->getMessage());
////        \Log::error('队列任务执行失败'."\n".date('Y-m-d H:i:s'));
//
//    }
}
